$(function () {
    findAll();
});

function findAll() {
    $.ajax({
        url: '/news/findAllNews',
        data: '',
        type: 'get',
        dataType: 'json',
        success: function (data) {
            console.log(data.data.NewsModel,"00000000");
            setProductData(data.data.NewsModel);
        }
    })
}

function setProductData(data) {
    let html = '';
    html+='<div onclick="change('+data[0].id+')"">\n' +
        '                    <div><img src="../img/w72s.jpg" width="350px"></div>\n' +
        '                    <div>\n' +
        '                        <div>'+data[0].name+'</div>\n' +
        '                        <div>'+data[0].title+'\n' +
        '                        </div>\n' +
        '                        <div>[详细]</div>\n' +
        '                        <div>'+data[0].createTime+'</div>\n' +
        '                    </div>\n' +
        '                </div>';
html+='<div>';
    for (let i = 1; i < data.length; i++) {
        html +='<div onclick="change('+data[i].id+')">\n' +
            '                        <div>'+data[i].name+'</div>\n' +
            '                        <div>'+data[i].createTime+'</div>\n' +
            '                    </div>'
    }
    html+='</div>';
    $("#news").html(html);
    // console.log($("#news").html())
}
function change(id){
    sessionStorage.setItem("id",id);
    location.href = '/front/html/newPage.html';
}